// 示例方法，没有实际意义
export function trim(str: string) {
  return str.trim();
}

// 判断是移动或PC 端
export function browserRedirect() {
  let _isPc = true;

  const sUserAgent: any = navigator.userAgent.toLowerCase();
  const bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
  const bIsIphoneOs = sUserAgent.match(/iphone os/i) == 'iphone os';
  const bIsMidp = sUserAgent.match(/midp/i) == 'midp';
  const bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
  const bIsUc = sUserAgent.match(/ucweb/i) == 'ucweb';
  const bIsAndroid = sUserAgent.match(/android/i) == 'android';
  const bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
  const bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';
  if (
    !(
      bIsIpad ||
      bIsIphoneOs ||
      bIsMidp ||
      bIsUc7 ||
      bIsUc ||
      bIsAndroid ||
      bIsCE ||
      bIsWM
    )
  ) {
    _isPc = true;
  } else {
    _isPc = false;
  }

  // ?logintype=forcepcforcepc:  移动端使用pc端布局。nofb: 移除页面fb 聊天
  // const _tc_c_type = get_local_cache('tc_community_type')
  // const _querydata = getQueryStringArgs();
  //   const _isapp = false
  // if (_querydata) {
  //   _querydata.logintype && _querydata.logintype == 'forcepc' && (_isPc = true)
  // }
  // if (_tc_c_type) {
  //   _tc_c_type && _tc_c_type == 'forcepc' && (_isPc = true)
  // }
  return _isPc;
}

export // 指定长度和基数
  function uuid(len = 20, radix = 20) {
  var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  var uuid = [],
    i;
  radix = radix || chars.length;

  if (len) {
    // Compact form
    for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
  } else {
    // rfc4122, version 4 form
    var r;

    // rfc4122 requires these characters
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    uuid[14] = '4';

    // Fill in random data.  At i==19 set the high bits of clock sequence as
    // per rfc4122, sec. 4.1.5
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | Math.random() * 16;
        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
      }
    }
  }

  return uuid.join('');
}


export function PositionArray(userList = [Object], from: string) {
  userList.map((item, index) => {
    if (item.name == from) {
      userList.unshift(userList.splice(index, 1)[0]);
    }
  });
  return userList;
}
